/**
 * created by uu, 16/07/15
 * #                                                   #
 * #                       _oo0oo_                     #
 * #                      o8888888o                    #
 * #                      88" . "88                    #
 * #                      (| -_- |)                    #
 * #                      0\  =  /0                    #
 * #                    ___/`---'\___                  #
 * #                  .' \\|     |# '.                 #
 * #                 / \\|||  :  |||# \                #
 * #                / _||||| -:- |||||- \              #
 * #               |   | \\\  -  #/ |   |              #
 * #               | \_|  ''\---/''  |_/ |             #
 * #               \  .-\__  '-'  ___/-. /             #
 * #             ___'. .'  /--.--\  `. .'___           #
 * #          ."" '<  `.___\_<|>_/___.' >' "".         #
 * #         | | :  `- \`.;`\ _ /`;.`/ - ` : | |       #
 * #         \  \ `_.   \_ __\ /__ _/   .-` /  /       #
 * #     =====`-.____`.___ \_____/___.-`___.-'=====    #
 * #                       `=---='                     #
 * #     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~   #
 * #                                                   #
 * #               佛祖保佑         永无BUG            #
 * #                                                   #
 */
package com.hemaapp.yjnh.activity;

import android.content.Intent;
import android.graphics.Paint;
import android.graphics.drawable.BitmapDrawable;
import android.os.Bundle;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.android.uu.view.AutoChangeViewPager;
import com.android.uu.view.UUHorizonalScrollView;
import com.hemaapp.BaseConfig;
import com.hemaapp.hm_FrameWork.HemaNetTask;
import com.hemaapp.hm_FrameWork.result.HemaArrayResult;
import com.hemaapp.hm_FrameWork.result.HemaBaseResult;
import com.hemaapp.hm_FrameWork.result.HemaPageArrayResult;
import com.hemaapp.hm_FrameWork.view.RefreshLoadmoreLayout;
import com.hemaapp.yjnh.BaseActivity;
import com.hemaapp.yjnh.BaseHttpInformation;
import com.hemaapp.yjnh.BaseUtil;
import com.hemaapp.yjnh.R;
import com.hemaapp.yjnh.adapter.AgriculturalSortAdapter;
import com.hemaapp.yjnh.adapter.CmnProductionAdapter;
import com.hemaapp.yjnh.listener.OnBlogItemClickListener;
import com.hemaapp.yjnh.bean.AdImage;
import com.hemaapp.yjnh.bean.Blog;
import com.hemaapp.yjnh.bean.BlogType;
import com.hemaapp.yjnh.bean.EventBusConfig;
import com.hemaapp.yjnh.bean.EventBusMsg;
import com.hemaapp.yjnh.bean.User;
import com.hemaapp.yjnh.utils.ImageUtils;
import com.hemaapp.yjnh.utils.LoginUtil;
import com.hemaapp.yjnh.view.ImageCarouselBanner;

import java.util.ArrayList;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;
import de.greenrobot.event.EventBus;
import de.greenrobot.event.Subscribe;
import xtom.frame.util.XtomSharedPreferencesUtil;
import xtom.frame.util.XtomToastUtil;
import xtom.frame.util.XtomWindowSize;
import xtom.frame.view.XtomListView;
import xtom.frame.view.XtomRefreshLoadmoreLayout;

/**
 * 首页中的农需
 */
public class AgriculturalDemandActivity extends BaseActivity {

    @Bind(R.id.tv_search)
    TextView tvSearch;
    @Bind(R.id.image_carousel_banner)
    ImageCarouselBanner imageCarouselBanner;
    @Bind(R.id.vp_sort)
    ViewPager vpSort;
    @Bind(R.id.rdgp_sort)
    RadioGroup rdgpSort;
    @Bind(R.id.tv_nearly)
    TextView tvNearly;
    @Bind(R.id.layout_nearly)
    LinearLayout layoutNearly;
    @Bind(R.id.scroll_nearly)
    UUHorizonalScrollView scrollNearly;
    @Bind(R.id.tv_default_sort)
    TextView tvDefaultSort;
    @Bind(R.id.iv_default_sort)
    ImageView ivDefaultSort;
    @Bind(R.id.line_default_sort)
    View lineDefaultSort;
    @Bind(R.id.layout_default_sort)
    RelativeLayout layoutDefaultSort;
    @Bind(R.id.tv_price_sort)
    TextView tvPriceSort;
    @Bind(R.id.iv_price_sort)
    ImageView ivPriceSort;
    @Bind(R.id.line_price_sort)
    View linePriceSort;
    @Bind(R.id.layout_price_sort)
    RelativeLayout layoutPriceSort;
    @Bind(R.id.tv_sales_sort)
    TextView tvSalesSort;
    @Bind(R.id.iv_sales_sort)
    ImageView ivSalesSort;
    @Bind(R.id.line_sales_sort)
    View lineSalesSort;
    @Bind(R.id.layout_sales_sort)
    RelativeLayout layoutSalesSort;
    private TextView titleText;
    private ImageButton titleLeft;
    private TextView titleRight;

    private RefreshLoadmoreLayout layoutRefresh;
    private View headerView;
    private XtomListView listview;

    private int page;
    private String province;//当前选择的城市
    private String city;//当前选择的城市
    private String ordertype = "2";//1降序；2升序
    private String orderby = "1";//1智能排序；6价格排序；2销量排序
    private ArrayList<AdImage> imgs = new ArrayList<AdImage>();
    private ArrayList<Blog> datas = new ArrayList<Blog>();
    private ArrayList<Blog> nearlyDatas = new ArrayList<Blog>();
    private ArrayList<BlogType> types = new ArrayList<>();
    private AgriculturalSortAdapter sortAdapter;
    private CmnProductionAdapter adapter;
    private int groupWide = 0;//推荐商品每一组数据的宽度
    private int groupNum = 3;//根据手机屏幕不同需要显示的推荐商品组的数量也不一样，最少3个
    private int screenWide = 0;//当前屏幕的宽度
    private LoginUtil.LoginCallBack loginCallBack;
    private User user;

    @Override
    public void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_agricultural);
        super.onCreate(savedInstanceState);
        user = getApplicationContext().getUser();
        EventBus.getDefault().register(this);
        //2016.10.31 start 为了和iOS一致，这里田家、乐乐、走走、农需的地区都单独保存
//		province = XtomSharedPreferencesUtil.get(mContext, "province");
//		city = XtomSharedPreferencesUtil.get(mContext, "city");
        province = XtomSharedPreferencesUtil.get(mContext, "province_agriculture");
        city = XtomSharedPreferencesUtil.get(mContext, "city_agriculture");
        if (isNull(province) || isNull(city)) {
            province = XtomSharedPreferencesUtil.get(mContext, "province");
            city = XtomSharedPreferencesUtil.get(mContext, "city");
        }
        //2016.10.31 end 为了和iOS一致，这里田家、乐乐、走走、农需的地区都单独保存
        screenWide = XtomWindowSize.getWidth(mContext);
        init();
    }

    @Override
    public void onDestroy() {
        EventBus.getDefault().unregister(this);
        super.onDestroy();
    }
    private void init() {
        //初始化listivew的header部分
        headerView = LayoutInflater.from(mContext).inflate(R.layout.header_activity_agricultural_demand, null);
        ButterKnife.bind(this, headerView);
        listview.addHeaderView(headerView);
        titleRight.setText(city);
        getNetWorker().getBlogTypeList("2", "0");//商品分类
        getNetWorker().ModelADList("5", city);//广告
        getNetWorker().blogList("17", "无", "1", "1", "", "", "", "", "", ""
                , "", "", province, "", "0");//获取周边农需
        getNetWorker().blogList("17", "无", orderby, ordertype, "", "", "1", "", "", ""
                , "", "", city, "", page+"");//获取推荐的农需
    }

    @Override
    protected void findView() {
        titleText = (TextView) findViewById(R.id.title_text);
        titleLeft = (ImageButton) findViewById(R.id.title_left_btn);
        titleRight = (TextView) findViewById(R.id.tv_title_right);

        layoutRefresh = (RefreshLoadmoreLayout) findViewById(R.id.refreshLoadmoreLayout);
        listview = (XtomListView) findViewById(R.id.listview);
    }

    @Override
    protected void setListener() {
        titleText.setText("农需");
        titleRight.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent itProvince = new Intent(mContext, CityActivity.class);
                itProvince.putExtra("type", 1);
                itProvince.putExtra("parent_id", "-1");
                startActivityForResult(itProvince, 1);
            }
        });
        titleLeft.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        layoutRefresh.setOnStartListener(new XtomRefreshLoadmoreLayout.OnStartListener() {
            @Override
            public void onStartRefresh(XtomRefreshLoadmoreLayout xtomRefreshLoadmoreLayout) {
                page = 0;
                getNetWorker().getBlogTypeList("2", "0");//商品分类
                getNetWorker().ModelADList("5", city);//广告
                getNetWorker().blogList("17", "无", "1", "1", "", "", "", "", "", ""
                        , "", "", province, "", "0");//获取周边农需
                getNetWorker().blogList("17", "无", orderby, ordertype, "", "", "1", "", "", ""
                        , "", "", city, "", page+"");//获取推荐的农需
            }

            @Override
            public void onStartLoadmore(XtomRefreshLoadmoreLayout xtomRefreshLoadmoreLayout) {
                page++;
                getNetWorker().blogList("17", "无", orderby, ordertype, "", "", "1", "", "", ""
                        , "", "", city, "", page+"");
            }
        });
    }

    @OnClick({R.id.tv_search, R.id.tv_nearly, R.id.layout_default_sort, R.id.layout_price_sort, R.id.layout_sales_sort})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.tv_search:
                Intent itSearch = new Intent(mContext, SearchActivity.class);
                itSearch.putExtra("assort", "农需");
                itSearch.putExtra("type", -1);//搜索类型
                startActivity(itSearch);
                break;
            case R.id.tv_nearly:
                Intent it = new Intent(mContext, CmnProductionListWithSortActivity.class);
                it.putExtra("title", "周边农需");
                it.putExtra("keytype", "17");
                it.putExtra("keyid", "无");
                it.putExtra("keyword", "");
                it.putExtra("saleflag", "");
                it.putExtra("topflag", "");
                it.putExtra("cheapflag", "");
                it.putExtra("score_percent", "");
                it.putExtra("seller_id", "");
                it.putExtra("district_name", city);
                mContext.startActivity(it);
                break;
            case R.id.layout_default_sort:
                if (orderby.equals("1")) {//智能排序
                    ordertype = ordertype.equals("1")?"2":"1";
                    getNetWorker().blogList("17", "无", orderby, ordertype, "", "", "1", "", "", ""
                            , "", "", city, "", page+"");
                    if (ordertype.equals("2"))
                        ivDefaultSort.setRotation(0);
                    else
                        ivDefaultSort.setRotation(180);
                    return;
                }else {
                    resetSort();
                    page = 0;
                    orderby = "1";
                    ivPriceSort.setRotation(0);
                    ivSalesSort.setRotation(0);
                    tvDefaultSort.setTextColor(getResources().getColor(R.color.theme_orange));
                    lineDefaultSort.setVisibility(View.VISIBLE);
                    getNetWorker().blogList("17", "无", orderby, ordertype, "", "", "1", "", "", ""
                            , "", "", city, "", page+"");
                }
                break;
            case R.id.layout_price_sort:
                if (orderby.equals("6")) {
                    ordertype = ordertype.equals("1")?"2":"1";
                    getNetWorker().blogList("17", "无", orderby, ordertype, "", "", "1", "", "", ""
                            , "", "", city, "", page+"");
                    if (ordertype.equals("2"))
                        ivPriceSort.setRotation(0);
                    else
                        ivPriceSort.setRotation(180);
                }else {
                    resetSort();
                    page = 0;
                    orderby = "6";
                    ordertype = "2";
                    ivDefaultSort.setRotation(0);
                    ivSalesSort.setRotation(0);
                    tvPriceSort.setTextColor(getResources().getColor(R.color.theme_orange));
                    linePriceSort.setVisibility(View.VISIBLE);
//                    ivPriceSort.setImageResource(R.mipmap.group_arrow_2);
                    getNetWorker().blogList("17", "无", orderby, ordertype, "", "", "1", "", "", ""
                            , "", "", city, "", page+"");
                }
                break;
            case R.id.layout_sales_sort:
                if (orderby.equals("2")) {
                    ordertype = ordertype.equals("1")?"2":"1";
                    getNetWorker().blogList("17", "无", orderby, ordertype, "", "", "1", "", "", ""
                            , "", "", city, "", page+"");
                    if (ordertype.equals("2"))
                        ivSalesSort.setRotation(0);
                    else
                        ivSalesSort.setRotation(180);
                }else {
                    resetSort();
                    page = 0;
                    orderby = "2";
                    ordertype = "2";
                    ivDefaultSort.setRotation(0);
                    ivPriceSort.setRotation(0);//将价格排序恢复
                    tvSalesSort.setTextColor(getResources().getColor(R.color.theme_orange));
                    lineSalesSort.setVisibility(View.VISIBLE);
//                    ivSalesSort.setImageResource(R.mipmap.group_arrow_2);
                    getNetWorker().blogList("17", "无", orderby, ordertype, "", "", "1", "", "", ""
                            , "", "", city, "", page+"");
                }
                break;
        }
    }

    private void resetSort() {
        tvDefaultSort.setTextColor(getResources().getColor(R.color.text_black));
        tvPriceSort.setTextColor(getResources().getColor(R.color.text_black));
        tvSalesSort.setTextColor(getResources().getColor(R.color.text_black));
        lineDefaultSort.setVisibility(View.GONE);
        linePriceSort.setVisibility(View.GONE);
        lineSalesSort.setVisibility(View.GONE);
    }
    @Override
    protected void callBeforeDataBack(HemaNetTask netTask) {
        BaseHttpInformation information = (BaseHttpInformation) netTask
                .getHttpInformation();
        switch (information) {
            case MODELAD_LIST:
            case BLOG_LIST:
            case BLOGTYPE_LIST:
                showProgressDialog("请稍候");
                break;
            default:
                break;
        }
    }

    @Override
    protected void callAfterDataBack(HemaNetTask netTask) {
        BaseHttpInformation information = (BaseHttpInformation) netTask
                .getHttpInformation();
        switch (information) {
            case MODELAD_LIST:
            case BLOG_LIST:
            case BLOGTYPE_LIST:
                cancelProgressDialog();
                break;
            default:
                break;
        }
    }

    @Override
    protected void callBackForServerSuccess(HemaNetTask netTask,
                                            HemaBaseResult baseResult) {
        BaseHttpInformation information = (BaseHttpInformation) netTask
                .getHttpInformation();
        switch (information) {
            case MODELAD_LIST:
                HemaPageArrayResult<AdImage> aResult = (HemaPageArrayResult<AdImage>) baseResult;
                if (aResult == null || aResult.getObjects() == null)
                    return;
                if (imgs == null) {
                    imgs = new ArrayList<AdImage>();
                } else {
                    imgs.clear();
                }
                imgs.addAll(aResult.getObjects());
                initPager();
                break;
            case BLOG_LIST:
                String topflag = netTask.getParams().get("topflag");
                HemaPageArrayResult<Blog> bResult = (HemaPageArrayResult<Blog>) baseResult;
                if (bResult == null || bResult.getObjects() == null)
                    return;
                if (!topflag.equals("1")) {//是周边的农需
                    nearlyDatas.clear();
                    nearlyDatas.addAll(bResult.getObjects());
                    setGoods();
                }else {
                    if (page == 0) {// 刷新
                        layoutRefresh.refreshSuccess();
                        datas.clear();
                        this.datas.addAll(bResult.getObjects());
                    } else {
                        layoutRefresh.loadmoreSuccess();
                        if (bResult.getObjects().size() > 0) {
                            this.datas.addAll(bResult.getObjects());
                        } else {
                            layoutRefresh.setLoadmoreable(false);
                            XtomToastUtil.showShortToast(mContext, "已经到最后啦");
                        }
                    }
                    refreshData();
                }
                break;
            case BLOGTYPE_LIST:
                HemaArrayResult<BlogType> typeResult = (HemaArrayResult<BlogType>) baseResult;
                if (typeResult == null || typeResult.getObjects() == null)
                    return;
                types.clear();
                BlogType blogType = new BlogType();
                blogType.setName("全部");
                types.add(blogType);
                types.addAll(typeResult.getObjects());
                initSort();
                break;
            default:
                break;
        }
    }

    @Override
    protected void callBackForServerFailed(HemaNetTask netTask,
                                           HemaBaseResult baseResult) {
        BaseHttpInformation information = (BaseHttpInformation) netTask
                .getHttpInformation();
        switch (information) {
            case MODELAD_LIST:
            case BLOG_LIST:
                if (page == 0) {// 刷新
                    layoutRefresh.refreshFailed();
                }else {
                    layoutRefresh.loadmoreFailed();
                }
                XtomToastUtil.showShortToast(mContext, "获取商品信息失败，"+baseResult.getMsg());
                break;
            case BLOGTYPE_LIST:
                XtomToastUtil.showShortToast(mContext, "获取分类失败，"+baseResult.getMsg());
                break;
            default:
                break;
        }
    }

    @Override
    protected void callBackForGetDataFailed(HemaNetTask netTask, int failedType) {
        BaseHttpInformation information = (BaseHttpInformation) netTask
                .getHttpInformation();
        switch (information) {
            case MODELAD_LIST:
            case BLOG_LIST:
                if (page == 0) {// 刷新
                    layoutRefresh.refreshFailed();
                }else {
                    layoutRefresh.loadmoreFailed();
                }
                XtomToastUtil.showShortToast(mContext, "获取商品信息失败，请稍后再试");
                break;
            case BLOGTYPE_LIST:
                XtomToastUtil.showShortToast(mContext, "获取分类失败，请稍后再试");
                break;
            default:
                break;
        }
    }

    private void initSort() {
        int dotSize = ((BitmapDrawable) mContext.getResources().getDrawable(
                R.drawable.dot_n)).getBitmap().getWidth();
        int page = (types.size()-1) / 8 + 1;
        rdgpSort.removeAllViews();
        for (int i = 0; i < page; i++) {
            RadioButton button = new RadioButton(mContext);
            button.setButtonDrawable(R.drawable.ad_show_indicator);
            button.setId(i);
            button.setClickable(false);
            LinearLayout.LayoutParams params2 = new LinearLayout.LayoutParams(
                    (i == page - 1) ? dotSize : dotSize * 2, dotSize);
            button.setLayoutParams(params2);
            if (i == 0)
                button.setChecked(true);
            rdgpSort.addView(button);
        }

        if (sortAdapter == null) {
            sortAdapter = new AgriculturalSortAdapter(mContext, types);
            vpSort.setAdapter(sortAdapter);
            vpSort.setOnPageChangeListener(new ViewPager.OnPageChangeListener() {
                @Override
                public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {

                }

                @Override
                public void onPageSelected(int position) {
                    RadioButton rbt = (RadioButton) rdgpSort.getChildAt(position);
                    if (rbt != null)
                        rbt.setChecked(true);
                }

                @Override
                public void onPageScrollStateChanged(int state) {

                }
            });
        }else
            sortAdapter.notifyDataSetChanged();
    }

    private void initPager() {
        ArrayList<String> urls = new ArrayList<>();
        for (AdImage item : imgs) {
            urls.add(item.getImgurl());
        }
        imageCarouselBanner.getLayoutParams().height = XtomWindowSize.getWidth(mContext)/2;
        imageCarouselBanner.onInstance(mContext, urls, R.drawable.ad_show_indicator,
                new ImageCarouselHeadClickListener(mContext, imgs, "2"));
    }

    private void refreshData() {
        if (adapter == null) {
            adapter = new CmnProductionAdapter(mContext, datas);
            adapter.setEmptyString("暂无推荐商品");
            adapter.setItemClickListener(new OnBlogItemClickListener() {
                @Override
                public void onClickListener(int position) {
                    Intent it = new Intent(mContext, CmnProductionDetailActivity.class);
                    it.putExtra("blog_id", datas.get(position).getId());
                    mContext.startActivity(it);
                }

                @Override
                public void onCartListener(final int position) {
                    loginCallBack = new LoginUtil.LoginCallBack() {
                        @Override
                        public void onLogin() {
                            getNetWorker().cartAdd(user.getToken(), datas.get(position).getId(), "1", "0");
                            loginCallBack = null;
                        }
                    };
                    LoginUtil.getInstance(mContext, loginCallBack);
                }
            });
            listview.setAdapter(adapter);
        } else {
            adapter.notifyDataSetChanged();
        }
    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (RESULT_OK != resultCode) {
            return;
        }
        if (requestCode == 1) {
            if (data == null) {
                return;
            }
            city = getCityName();
            province = data.getStringExtra("parentName");
            titleRight.setText(city);
            page = 0;
            getNetWorker().ModelADList("5", city);//广告
            getNetWorker().blogList("17", "无", "1", "1", "", "", "", "", "", ""
                    , "", "", province, "", "0");
            getNetWorker().blogList("17", "无", orderby, ordertype, "", "", "1", "", "", ""
                    , "", "", city, "", page+"");//获取全部的农需
            //2016.10.31 start 为了和iOS一致，这里田家、乐乐、走走、农需的地区都单独保存
            XtomSharedPreferencesUtil.save(mContext, "province_agriculture", province);
            XtomSharedPreferencesUtil.save(mContext, "city_agriculture", city);
            //2016.10.31 end 为了和iOS一致，这里田家、乐乐、走走、农需的地区都单独保存
        }
        super.onActivityResult(requestCode, resultCode, data);
    }


    /**显示推荐的商品
     *
     */
    private void setGoods() {
        groupWide = 0;
        //动态添加多个商品
        if (layoutNearly.getChildCount() != 0) {
            layoutNearly.removeAllViews();
        }
        for (int j = 0; j < groupNum; j++) {
            for (int i = 0; i < nearlyDatas.size(); i++) {
                Blog blog = nearlyDatas.get(i);
                View view = LayoutInflater.from(mContext).inflate(
                        R.layout.layout_recommend_goods, layoutNearly, false);
                ItemViewHolder ivHolder = new ItemViewHolder();
                itemFindView(view, ivHolder);
                setItem(i, blog, view, ivHolder);
                if (j == 0) {
                    view.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED),
                            View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED));
                    groupWide += view.getMeasuredWidth();
                }
                view.setTag(blog);
                view.setOnClickListener(new OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        Blog blog1 = (Blog) v.getTag();
                        Intent intent = BaseUtil.createBlogIntent(mContext, blog1.getType());
                        intent.putExtra("blog_id", blog1.getId());
                        startActivity(intent);
                    }
                });
            }
            if (j == 0 && groupWide > 0) {
                if (groupWide < screenWide) {
                    groupNum = 1;
                } else {
                    groupNum += (screenWide / groupWide);
                }
            }
        }
        scrollNearly.setGroupWide(groupWide);
    }

    private class ItemViewHolder {
        private ImageView backImage;
        private TextView name;
        private TextView price;
        private TextView oldPrice;
    }

    private void itemFindView(View view, ItemViewHolder ivHolder) {
        ivHolder.backImage = (ImageView) view.findViewById(R.id.iv_goods);
        ivHolder.name = (TextView) view.findViewById(R.id.tv_name);
        ivHolder.price = (TextView) view.findViewById(R.id.tv_price);
        ivHolder.oldPrice = (TextView) view.findViewById(R.id.tv_old_price);
    }

    private void setItem(int i, Blog child, View view, ItemViewHolder ivHolder) {
        ImageUtils.loadSmalImage(mContext, child.getImgurl(), ivHolder.backImage);
        ivHolder.name.setText(child.getName());
        ivHolder.price.setText(child.getPrice());
        ivHolder.oldPrice.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG ); //中间横线
        ivHolder.oldPrice.setText("¥"+child.getOldprice());
        layoutNearly.addView(view);
    }


    @Subscribe
    public void onEventMainThread(EventBusMsg msg) {
        if (msg.getType() == EventBusConfig.USER) {
            this.user = msg.getUser();
            if (loginCallBack != null)
                loginCallBack.onLogin();
        }
    }
}
